#include <iostream>
#include <math.h>
using namespace std;

int genTriNum(int place){

    int sum = 0;
    for(int i = place; i > 0; i--){
        sum += i;
    }return sum;
}

int numOfFactors(int num){

    int factors = 1;
    for(int i = 2; i<=num/2; i++){
        if(num%i==0)
            factors++;
    }
    if(num!=1)
        return factors+1;
    return 1;
}

int numOfFactors2(int num){
    int factors = 1;
    int sqrtOfNum = sqrt(num);
    for(int i = 2; i<= sqrtOfNum; i ++){
        if(num%i==0){
            if(i!=sqrtOfNum)
                factors+=2;
            else
                factors++;
        }
    }
    if(num!=1)
        return factors+1;
    return 1;
}

int firstWithNumFactors(int num){

    int value = 0;
    int numFac;
    for(int i = 1; i < 20000; i++){
        value += i;
        numFac = numOfFactors2(value);
        cout << i << "\t| " << value << "\t| " << numFac <<endl;
        if( numFac > num ){
            return value;
        }
    }

    return 0;

}

int main(){
    cout << endl << "\nAnswer: " << firstWithNumFactors(500) << endl;
    return 0;
}
